// use multithreading to speed up the process

fn is_prime(n: u64) -> bool {
    if n < 2 {
        return false;
    }
    for i in 2..=(n as f64).sqrt() as u64 {
        if n % i == 0 {
            return false;
        }
    }
    true
}

fn is_square(n: u64) -> bool {
    let sqrt_n = (n as f64).sqrt() as u64;
    sqrt_n * sqrt_n == n
}

pub fn goldbach_conjecture() -> u64 {
    let mut found = 0;
    let mut sum = 0;
    // n = m + 2*k*k
    for n in (3..).step_by(2) {
        if found >= 2 {
            break;
        }
        if is_prime(n) {
            continue;
        }

        let mut found_m = false;
        
        for m in (3..n).step_by(2) {
            let remainings = n - m;
            if is_square(remainings / 2) {
                if is_prime(m) {
                    found_m = true;
                    break;
                }
            }
        }

        if !found_m {
            found += 1;
            sum += n;
        }
    }
    sum
}
